package controllers

import (
	"fmt"

	"gitee.com/wao520/obtain_data/global"
	"gitee.com/wao520/obtain_data/pkg/result"
	"gitee.com/wao520/obtain_data/pkg/validCheck"
	"gitee.com/wao520/obtain_data/request"
	"gitee.com/wao520/obtain_data/service"
	"github.com/gin-gonic/gin"
)

type ArticleController struct{}

func NewArticleController() *ArticleController {
	return &ArticleController{}
}

// 得到一篇文章的详情
func (a *ArticleController) GetOne(c *gin.Context) {
	result := result.NewResult(c)
	param := request.ArticleRequest{ID: validCheck.StrTo(c.Param("id")).MustUInt64()}
	valid, _ := validCheck.BindAndValid(c, &param)
	if !valid {
		result.Error(global.ErrParam)
		return
	}
	if param.ID == 100 {
		var z int = 0
		var i int = 100 / z
		fmt.Println("i:%i", i)
	}
	articleOne, err := service.GetOneArticle(param.ID)
	if err != nil {
		result.Error(global.ErrArticleNot)
	} else {
		result.Success(&articleOne)
	}
}
